<template>
    <div v-loading="loading">
        <div class="note-div">
            说明：
            <div v-for="(item, idx) in NoteArray" :key="idx" class="note-item">
                {{ idx + 1 }}、{{ item }}
            </div>
        </div>
        <el-form :model="tableBaseInfo" style="width: 90%;margin: 20px auto;" :disabled="!isEdit">
            <el-form-item label="使用单位名称:" prop="usingUnit">
                <el-input v-model="tableBaseInfo.usingUnit" placeholder="请输入" clearable />
            </el-form-item>
            <div class="flex-stb">
                <el-form-item label="设备代码:" prop="code">
                    <el-input v-model="tableBaseInfo.code" placeholder="请输入" clearable />
                </el-form-item>
                <el-form-item label="设备类别::" prop="categoryName">
                    <el-select v-model="tableBaseInfo.categoryName" placeholder="请选择" clearable style="width: 380px">
                        <el-option label="电梯" value="1" />
                    </el-select>
                </el-form-item>
            </div>
            <el-form-item label="检测日期:" prop="detectionDate">
                <el-date-picker v-model="tableBaseInfo.detectionDate" placeholder="请选择" type="date"
                    value-format="YYYY-MM-DD" style="width: 380px" />
            </el-form-item>
            <el-form-item label="检测人员" prop="decetionPeoples">
                <el-input v-model="tableBaseInfo.decetionPeoples" placeholder="请输入" :disabled="true" clearable />
            </el-form-item>

            <div class="form-container">
                <div class="flex-stb">
                    <el-form-item label="使用单位名称:" prop="usingUnit">
                        <el-input v-model="tableBaseInfo.usingUnit" placeholder="请输入" clearable />
                    </el-form-item>
                    <el-form-item label="统一社会信用代码:" prop="uniformSocialCreditNo">
                        <el-input v-model="tableBaseInfo.uniformSocialCreditNo" placeholder="请输入" clearable />
                    </el-form-item>
                </div>
                <el-form-item label="安装地点:" prop="installAddress">
                    <el-input v-model="tableBaseInfo.installAddress" placeholder="请输入" clearable />
                </el-form-item>
                <div class="flex-stb">
                    <el-form-item label="设备品种:" prop="varietyName">
                        <el-input v-model="tableBaseInfo.varietyName" placeholder="请输入" clearable />
                    </el-form-item>
                    <el-form-item label="产品型号:" prop="productIdentifier">
                        <el-input v-model="tableBaseInfo.productIdentifier" placeholder="请输入" clearable />
                    </el-form-item>
                </div>
                <div class="flex-stb">
                    <el-form-item label="产品编号:" prop="code">
                        <el-input v-model="tableBaseInfo.code" placeholder="请输入" clearable />
                    </el-form-item>
                    <el-form-item label="单位内编号:" prop="unityIdentifier">
                        <el-input v-model="tableBaseInfo.unityIdentifier" placeholder="请输入" clearable />
                    </el-form-item>
                </div>
                <div class="flex-stb">
                    <el-form-item label="使用登记证编号:" prop="useRegistrationCode">
                        <el-input v-model="tableBaseInfo.useRegistrationCode" placeholder="请输入" clearable />
                    </el-form-item>
                    <el-form-item label="安全管理人员:" prop="safetyManager">
                        <el-input v-model="tableBaseInfo.safetyManager" placeholder="请输入" clearable />
                    </el-form-item>
                </div>
                <div class="flex-stb">
                    <el-form-item label="制造单位名称:" prop="designUnityName">
                        <el-input v-model="tableBaseInfo.designUnityName" placeholder="请输入" clearable />
                    </el-form-item>
                    <el-form-item label="制造日期:" prop="designDate">
                        <el-input v-model="tableBaseInfo.designDate" placeholder="请输入" clearable />
                    </el-form-item>
                </div>
                <div class="flex-stb">
                    <el-form-item label="改造单位名称:" prop="reformUnityName">
                        <el-input v-model="tableBaseInfo.reformUnityName" placeholder="请输入" clearable />
                    </el-form-item>
                    <el-form-item label="改造日期:" prop="reformDate">
                        <el-input v-model="tableBaseInfo.reformDate" placeholder="请输入" clearable />
                    </el-form-item>
                </div>
                <el-form-item label="维护保养单位名称:" prop="maintenanceUnity">
                    <el-input v-model="tableBaseInfo.maintenanceUnity" placeholder="请输入" clearable />
                </el-form-item>
                <el-form-item label="使用场所:" prop="usingAddress">
                    <el-input v-model="tableBaseInfo.usingAddress" placeholder="请输入" clearable />
                </el-form-item>
                <div>
                    <el-form-item label="是否增加电梯:" prop="isAdd">
                        <el-radio-group v-model="tableBaseInfo.isAdd">
                            <el-radio :label="1">是</el-radio>
                            <el-radio :label="0">否</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </div>

                <div class="form-item-title">设备技术参数</div>
                <div class="flex-flow">
                    <el-form-item v-for="(item, idx) in tableBaseInfo.dstProductParamDetailVOList" :key='idx'
                        :label="item.name">
                        <el-input v-model="item.content" placeholder="请输入" clearable style="width: 300px">
                        </el-input>
                    </el-form-item>
                </div>
                <el-form-item label="检测依据::" prop="entName">
                    <el-input v-model="tableBaseInfo.conductStandardStr" :disabled="true" placeholder="请输入" clearable />
                </el-form-item>

                <div class="form-item-title">主要检测仪器设备</div>
                <el-table :data="detectionDeviceList" @selection-change="handleSelectionChange"
                    style="margin-top: 30px;margin-left: 20px;margin-right: 10px;width: calc(100% - 40px);">
                    <el-table-column type="selection" width="55" />
                    <el-table-column type="index" width="50" label="序号" />
                    <el-table-column label="设备种类" align="center" prop="className" />
                    <el-table-column label="仪器名称" align="center" prop="name" />
                    <el-table-column label="仪器型号" align="center" prop="modelName" />
                    <el-table-column label="采购时间" align="center" prop="procureDate">
                        <template #default="scope">
                            {{ parseTime(scope.row.procureDate || '') }}
                        </template>
                    </el-table-column>
                    <el-table-column label="入库时间" align="center" prop="warehousingDate">
                        <template #default="scope">
                            {{ parseTime(scope.row.warehousingDate || '') }}
                        </template>
                    </el-table-column>
                    <el-table-column label="有效期至" align="center" prop="effectiveDate">
                        <template #default="scope">
                            {{ parseTime(scope.row.effectiveDate || '') }}
                        </template>
                    </el-table-column>
                    <el-table-column label="检定或校准机构" align="center" prop="verificationAgencyName" width="160px" />
                    <el-table-column label="供应商" align="center" prop="supplierName" />
                    <el-table-column label="数量" align="center" prop="amount" />
                    <el-table-column label="经办人" align="center" prop="handlerName" />
                </el-table>

                <div class="form-item-title">检测条件确认</div>
                <div>
                    <div v-for="(item, idx) in checkSureList" :key="idx" class="content-item">
                        {{ idx + 1 }}、{{ item.name }}
                    </div>
                </div>

                <div class="form-item-title">不符合情况及相关建议</div>
                <el-radio-group v-model="tableBaseInfo.hadNoPass" class="radio-class">
                    <div> <el-radio :label="1" size="large">无</el-radio></div>
                    <div> <el-radio :label="2" size="large">该电梯存在不符合，建议立即整改</el-radio></div>
                    <div> <el-radio :label="3" size="large">该电梯存在较严重的不符合，建议立即停用整改</el-radio></div>
                </el-radio-group>
                <div class="content-item" style="margin: 10px 100px;">
                    <div v-for="(item, idx) in noPassList" :key="idx" class="red-item">
                        <span style="margin-right: 10px;">({{ idx + 1 }})</span> {{ item[1].code }} ：{{ item[1].remark
                            ||
                            item[1].allName }}
                    </div>
                </div>

                <div class="form-item-title">检测结论</div>
                <div class="content-item">
                    {{ getIsAllPass() ? '所检测项目均符合《电梯自行检测规则》相应要求' : '该电梯存在不符合情况' }}
                </div>

                <div class="form-item-title">备注</div>
                <div style="margin-left: 100px;">下一年</div>
                <el-radio-group v-model="tableBaseInfo.nextYear" class="radio-class">
                    <div> <el-radio :label="1" size="large">检测</el-radio></div>
                    <div> <el-radio :label="2" size="large">检验</el-radio></div>
                </el-radio-group>
                <el-form-item label="日期::" prop="expirationDate" label-width="90px">
                    <el-date-picker v-model="tableBaseInfo.expirationDate" placeholder="请选择" type="date"
                        value-format="YYYY-MM-DD" style="width: 400px" />
                </el-form-item>
            </div>
        </el-form>

        <div class="checkitemop-div" v-if="isEdit">
            <!-- <div class="flex-v" style="margin-right: 20px;">
                <el-select v-model="tableSearchValue" filterable placeholder="选择或输入需要定位的项" style="width: 300px">
                    <el-option v-for="(item, idx) in checkItemOptions" :key="idx" :label="item.name" :value="item.value" />
                </el-select>
                <el-button type="primary" @click="toTablePosition">定位</el-button>
            </div> -->
            <el-button type="primary" @click="setAllPass">全部检测项设置为合格</el-button>
        </div>

        <div class="form-container detection-item-root">
            <el-table ref="tableRef" :data="checkItemList" height="500" :default-expand-all="true"
                style="width: calc(100% - 50px);margin-left: 50px;">
                <el-table-column label="" align="center" type="expand" prop="code" width="1">
                    <template #default="scope">
                        <!-- 附表 -->
                        <div v-if="scope.row.itemFormResponse && scope.row.itemFormResponse.id" class="schedule-root">
                            <div class="table-title">{{ scope.row.name }}({{ scope.row.itemFormResponse.name }})</div>

                            <!-- 噪声测试 -->
                            <div v-if="scope.row.itemFormResponse.name == '附表2'">
                                <div v-for="(item, idx) in scope.row.itemFormResponse.list" :key="idx"
                                    class="schedule-two-item">
                                    <div class="title">{{ item.title }}({{ item.unit }})</div>
                                    <div v-if="item.clist" class="flex">
                                        <div v-for="(citem, cidx) in item.clist" :key="cidx" class="item">
                                            <div class="c-title">{{ citem.name }}</div>
                                            <el-input v-model="citem.value" placeholder="请输入" :disabled="!isEdit" />
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- 平衡系数测试 -->
                            <div v-if="scope.row.itemFormResponse.name == '附表3'">
                                <div class="table-3-container">
                                    <div class="item-title">测试方法</div>
                                    <div class="method-item">
                                        <el-checkbox-group v-model="scope.row.itemFormResponse.table3MethodValue">
                                            <el-checkbox v-for="(item, idx) in scope.row.itemFormResponse.table3MethodList"
                                                :key="idx" :value="idx" class="cbox-item">
                                                <div>{{ item }}</div>
                                            </el-checkbox>
                                        </el-checkbox-group>
                                    </div>
                                    <div class="item-title">测试记录</div>
                                    <div v-for="(item, idx) in scope.row.itemFormResponse.table3Records" :key="idx"
                                        class="h-item">
                                        <div class="item">{{ item.title }}</div>
                                        <div class="input-div" v-for="(citem, cidx) in 4" :key="cidx">
                                            <el-input v-model="item.inputVal[cidx]" placeholder="请输入" :disabled="!isEdit" />
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- 平衡系数测试 -->
                            <div v-if="scope.row.itemFormResponse.name == '附表1'" class="table-floor-root">
                                <div class="flex-v">
                                    <div class="floor-title">
                                        <div>楼层</div>
                                    </div>
                                    <div class="floor-item">
                                        <div v-for="(item, idx) in scope.row.itemFormResponse.table1Records" :key="idx"
                                            class="floor">
                                            <el-input v-model="item.text" maxlength="10" placeholder="请输入" />
                                        </div>
                                    </div>
                                </div>
                                <div class="flex-v">
                                    <div class="floor-title">
                                        <div>间隙({{ scope.row.itemFormResponse.unit || '' }})</div>
                                    </div>
                                    <div class="floor-item">
                                        <div v-for="(item, idx) in scope.row.itemFormResponse.table1Records" :key="idx"
                                            class="value">
                                            <el-input v-model="item.value" maxlength="10" placeholder="请输入" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="检测编号" align="center" prop="code" width="120" />
                <el-table-column label="检测项目" align="center" prop="name" width="80" />
                <el-table-column label="项目名称" align="center" prop="allName" width="80" />
                <el-table-column label="内容与要求" align="center" prop="contentAndRequirements">
                    <template #default="scope">
                        <div>{{ scope.row.contentAndRequirements }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="检测方法" align="center" prop="note" width="270px">
                    <template #default="scope">
                        {{ scope.row.checkMethod }}
                    </template>
                </el-table-column>

                <el-table-column label="检测结果" align="center" prop="result" width="180">
                    <template #default="scope">
                        <el-select v-model="scope.row.chooseItemValue" placeholder="请选择" :disabled="!isEdit" clearable
                            @change="(e) => {
                                chooseChange(e, scope.$index, scope.row)
                            }">
                            <el-option v-for="(item, idx) in scope.row.chooseItemArray" :label="item" :value="idx" />
                        </el-select>

                        <div v-if="scope.row.inputItemsResult && scope.row.inputItemsResult.length > 0" class="flex-vhc-c">
                            <div class="flex-v" v-for="(ritem, ridx) in scope.row.inputItemsResult" :key="ridx"
                                style="margin-top: 10px;">
                                <div v-if="ritem.itemName">{{ ritem.itemName }}：</div>
                                <el-input v-model="ritem.value" placeholder="请输入" clearable :disabled="!isEdit"
                                    style="min-width: 70px !important;width: 70px !important;margin-right: 5px;">
                                </el-input>
                                <div v-if="ritem.unit">{{ ritem.unit }}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>

                <el-table-column label="备注" align="center" prop="remark" width="160">
                    <template #default="scope">
                        <el-input v-model="scope.row.remark" placeholder="请输入" clearable :disabled="!isEdit"
                            :autosize="{ minRows: 2, maxRows: 4 }" type="textarea" show-word-limit maxlength="200" />
                    </template>
                </el-table-column>

                <el-table-column v-if="props.isRectification" label="整改确认" align="center" prop="rectificationChooseResult"
                    width="125">
                    <template #default="scope">
                        <el-select v-model="detailsInfo.rectificationChooseResult" placeholder="请选择" clearable
                            :disabled="!isEdit">
                            <el-option label="符合" :value="0" />
                            <el-option label="不符合" :value="1" />
                        </el-select>
                    </template>
                </el-table-column>

                <el-table-column v-if="props.isRectification" label="整改确认备注" align="center" prop="rectificationRemark"
                    width="160">
                    <template #default="scope">
                        <el-input v-model="scope.row.rectificationRemark" placeholder="请输入" clearable :disabled="!isEdit"
                            :autosize="{ minRows: 2, maxRows: 4 }" type="textarea" show-word-limit maxlength="200" />
                    </template>
                </el-table-column>

                <el-table-column label="附件" align="center" prop="files" width="135">
                    <template #default="scope">
                        <div v-for="(item, idx) in scope.row.files" :key="idx" class="file-item-div">
                            <div class="txt">{{ item }}</div>
                            <el-icon color="#FF4500" @click="delFile(scope.$index, idx, item)" v-if="isEdit">
                                <CircleCloseFilled />
                            </el-icon>
                        </div>
                        <div style="margin-top: 5px;" v-if="isEdit">
                            <FileUpload :isShowTip="false"></FileUpload>
                        </div>
                    </template>
                </el-table-column>
            </el-table>

            <div class="form-item-title">是否需要整改</div>
            <el-radio-group v-model="tableBaseInfo.rectification" :disabled="!isEdit" class="radio-class">
                <div> <el-radio :label="0" size="large">否</el-radio></div>
                <div> <el-radio :label="1" size="large">是</el-radio></div>
            </el-radio-group>
        </div>
    </div>
</template>

<script setup>
import {
    apiGetSureDetectionInfo,
    apiGetDetectionSureCondition,
    apiGetDetectionItemList,
} from "@/api/detection";

import {
    apiGetInstrumentationList,
} from "@/api/device";

const { proxy } = getCurrentInstance();

const loading = ref(false)
const checkSureList = ref([])
const checkItemList = ref([])
const tableSearchValue = ref('')
const checkItemOptions = ref([])
const tableRef = ref(null)


const detailsInfo = ref({
    hadNoPass: '',
    detectionItemList: [{
        no: "A1.2.1.1",
        title: "通道及照明",
        //内容与要求
        contentAndRequirements: [
            '(1) 通往机器空间的通道保持通畅，相关人员能够安全、方便、无阻碍地使用，如果通往机器空间的通道高出楼梯所到平面不超过4.0m，可以采用固定的梯子作为通道',
            '(2) 进入机器空间的门附近的通道设有永久性电气照明'
        ],
        //检测方法
        testMethod: ['(1) 审查资料；'],
        //是否需要默认
        needDefault: true,
        //是否关键项
        isKeyItem: true,
        //输入项结果
        inputItemsResult: [
            { "itemName": "高", "unit": "mm", "value": 20 },
            { "itemName": "宽", "unit": "mm", "value": 20 }
        ],
        //备注结果
        remark: "",
        //选择结果（是否符合）
        chooseResult: '1',
        //是否检测（0-未检测、1-已检测）
        isCheck: false
    }, {
        no: "A1.2.1.2",
        title: "通道及照明",
        contentAndRequirements: [
            '(1) 通往机器空间的通道保持通畅，相关人员能够安全、方便、无阻碍地使用，如果通往机器空间的通道高出楼梯所到平面不超过4.0m，可以采用固定的梯子作为通道',
            '(2) 进入机器空间的门附近的通道设有永久性电气照明'
        ],
        testMethod: [],
        needDefault: true,
        isKeyItem: true,
        inputItemsResult: [],
        remark: "",
        chooseResult: '1',
        isCheck: false,
        scheduleList: [{
        }]
    }]
})


const NoteArray = ref([
    '本电梯检测原始记录依据《电梯自行检测规则》（TSG T7008-2023）',
    '检测使用仪器、量具其性能和精度应符合有关标准化的规定,并在国家计量部门定期检定的有效期内',
    '检测原始记录与检测报告一起存档，原始记录编号与平台系统中的检测报告编号一致',
    '检测原始记录必须有检测员签字及检测日期',

    '原始记录的“检测结果"栏要求量化的参数应按实测数据填写在检测结果栏中；无实测数据的根据观测到的状况，'
    + '在“检测结果"一栏中选择:分别为：“符合"、"不符合“；在备注一栏，'
    + '可输入对检测项目描述，在附件一栏，上传对应检测项相关文件附件；“JX"BL"“AL"QK"分别表示：“集选"、“并联"、“按钮"、“群控"',

    '标有*的项目为重要检测项目，其余项目为一般检测项目',
    '本次现场检测的条件必须符合检测要求时方能开展检测业务',
    '本记录对检测时的设备状况负责注',
])

const props = defineProps({
    info: {
        type: Object,
        default: () => {
            return {}
        }
    },
    isEdit: {
        type: Boolean,
        default: false
    },
    isRectification: {
        type: Boolean,
        default: false,
    },//是否是整改
});

const noPassList = ref(new Map()) //不符合情况的数据，以检测项的 id 为 key
const tableBaseInfo = ref({})
const detectionDeviceList = ref([])
const multipleSelection = ref([])

const handleSelectionChange = (val) => {
    multipleSelection.value = val || []
}


//选项变化
const chooseChange = (e, pIndex, row) => {
    if (e == 1) {
        noPassList.value.set(row.id, row)
    } else {
        noPassList.value.delete(row.id)
    }
    if (tableBaseInfo.value.hadNoPass == 1) {
        tableBaseInfo.value.hadNoPass = -1
    }

    if (noPassList.value.size > 0) {
        tableBaseInfo.value.rectification = 1
    } else {
        tableBaseInfo.value.rectification = 0
    }
}

const getIsAllPass = () => {
    return noPassList.value.size == 0
}


//获取基本信息
const getSureInfo = () => {
    loading.value = true
    apiGetSureDetectionInfo(detailsInfo.value.id).then(res => {
        loading.value = false
        if (res && res.data) {
            let peopleIds = []
            let decetionPeoples = []
            if (res.data.headWorker) {
                decetionPeoples.push(res.data.headWorker.name)
                peopleIds.push(res.data.headWorker.id)
            }
            if (res.data.staffWorkerList) {
                res.data.staffWorkerList.map(item => {
                    decetionPeoples.push(item.name)
                    peopleIds.push(item.id)
                })
            }
            res.data.peopleIds = peopleIds.join(',')
            res.data.conductStandardStr = res.data.conductStandardName + res.data.conductStandardNo
            res.data.decetionPeoples = decetionPeoples.join(',')
            res.data.rectification = 0
            tableBaseInfo.value = res.data
        }
    }).catch(err => {
        loading.value = false
    })
}

//获取检测条件
const getSureConditionInfo = () => {
    loading.value = true
    apiGetDetectionSureCondition({
        "productId": detailsInfo.value.productId,
        "categoryId": detailsInfo.value.categoryId
    }).then(res => {
        loading.value = false
        if (res && res.data) {
            checkSureList.value = res.data
        } else {
            checkSureList.value = []
        }
    }).catch(err => {
        loading.value = false
        checkSureList.value = []
    })
}

//获取检测项
const getDetecitonItem = () => {
    loading.value = true
    apiGetDetectionItemList({
        "id": detailsInfo.value.id,
        "id": 1,
        "pageNum": 1,
        "pageSize": 100
    }).then(res => {
        loading.value = false
        if (res && res.data) {
            let options = []
            let testList = []
            let tempList = res.data.records
            tempList.map((item, index) => {
                if (item.chooseItems && item.chooseItems.indexOf("[") != -1) {
                    let items = JSON.parse(item.chooseItems)
                    item.chooseItemArray = items
                }
                item.files = []
                if (item.imgs) {
                    if (item.imgs.indexOf(',') != -1) {
                        item.files = item.files.contact(item.imgs.split(','))
                    } else {
                        item.files.push(item.imgs)
                    }
                }
                if (item.videos) {
                    if (item.videos.indexOf(',') != -1) {
                        item.files = item.files.contact(item.videos.split(','))
                    } else {
                        item.files.push(item.videos)
                    }
                }
                options.push({
                    name: item.code + "(" + item.allName + ")",
                    value: index
                })

                //处理附表数据
                if (item.itemFormResponse) {
                    console.log(item.itemFormResponse)
                    if (item.itemFormResponse.content) {
                        let oInfo = {}
                        if (item.itemFormResponse.content.indexOf('"[') == 0) {
                            oInfo = JSON.parse(item.itemFormResponse.content)[0]
                        } else {
                            oInfo = JSON.parse(item.itemFormResponse.content)
                        }
                        if (item.itemFormResponse.name == "附表2") {
                            let clist = []
                            clist.push({
                                title: "机房噪声",
                                unit: oInfo.unit,
                                clist: oInfo.machineRoom || [],
                            })
                            clist.push({
                                title: "轿厢内噪声",
                                unit: oInfo.unit,
                                clist: oInfo.cabInter || [],
                            })
                            clist.push({
                                title: "开关门噪声",
                                unit: oInfo.unit,
                                clist: oInfo.openShutDoor || [],
                            })
                            clist.push({
                                title: "无机房电梯层门处噪声",
                                unit: oInfo.unit,
                                clist: oInfo.floor || [],
                            })
                            item.itemFormResponse.list = clist

                        } else if (item.itemFormResponse.name == '附表3') {
                            //测试方法
                            item.itemFormResponse.table3MethodValue = []
                            item.itemFormResponse.table3MethodList = []
                            for (let i = 0; i < oInfo.methods.length; i++) {
                                item.itemFormResponse.table3MethodList.push(oInfo.methods[i].name)
                            }
                            //测试记录
                            item.itemFormResponse.table3Records = []
                            let titems = oInfo.records.items
                            for (let i = 0; i < titems.length; i++) {
                                item.itemFormResponse.table3Records.push({
                                    title: titems[i].name,
                                    unit: titems[i].unit,
                                    value: titems[i].value,
                                    inputVal: ['', '', '', '',],
                                })
                            }
                        }

                    } else if (item.itemFormResponse.name == '附表1') {
                        item.itemFormResponse.table1Records = []
                        for (let i = 0; i < 18; i++) {
                            item.itemFormResponse.table1Records.push({
                                text: '',
                                value: '',
                            })
                        }
                    }
                }
            })
            checkItemList.value = tempList
            checkItemOptions.value = options
        } else {
            checkItemList.value = []
        }
    }).catch(err => {
        loading.value = false
        checkItemList.value = []
    })
}

//获取检测仪器
const getTaskDeviceInfo = () => {
    loading.value = true
    apiGetInstrumentationList({
        "pageNum": 1,
        "pageSize": 100,
    }).then(res => {
        loading.value = false
        if (res && res.data) {
            detectionDeviceList.value = res.data.records
        } else {
            detectionDeviceList.value = []
        }
    }).catch(err => {
        loading.value = false
        detectionDeviceList.value = []
    })
}


const setInfo = (val) => {
    if (val) {
        detailsInfo.value = val ? JSON.parse(JSON.stringify(val)) : {}
    } else if (props.info) {
        detailsInfo.value = JSON.parse(JSON.stringify(props.info))
    }
    if (detailsInfo.value.id) {
        getSureInfo()
        getSureConditionInfo()
        getDetecitonItem()
        getTaskDeviceInfo()
    }
}

setInfo()


watch(() => props.info, val => {
    setInfo(val)
})

const toTablePosition = () => {
    if (!tableSearchValue.value) {
        return proxy.$modal.msgError("请选择或输入需要定位的项");
    }
    const rowEl = tableRef.value.$el.querySelector(
        `.el-table__row:nth-child(${tableSearchValue.value})`
    );
    tableRef.value.scrollTo(0, rowEl.getBoundingClientRect().top)
    console.log(rowEl)
    console.log(rowEl.getBoundingClientRect())
}


//将所有检测项都设置为通过
const setAllPass = () => {
    if (checkItemList.value && checkItemList.value.length > 0) {
        let list = JSON.parse(JSON.stringify(checkItemList.value))
        list.map(item => {
            item.chooseItemValue = 0
        })
        checkItemList.value = list
    }
    noPassList.value.clear()
    tableBaseInfo.value.hadNoPass = 1
    tableBaseInfo.value.rectification = 0
}

//删除附件
const delFile = (rowIdx, idx, item) => {
    checkItemList.value[rowIdx].files.splice(idx, 1)
}

const getInputInfo = () => {
    let isOk = false
    let dInfo = detailsInfo.value
    let baseInfo = tableBaseInfo.value
    let result = {
        "registrationCode": baseInfo.useRegistrationCode,
        "taskId": dInfo.taskId,
        "detectionWorkers": baseInfo.peopleIds,
        "usingAddress": baseInfo.usingAddress,
        "isAddElevator": baseInfo.isAdd,
        "conductStandardName": '《电梯自行检测规则》',
        "conductStandardNo": 'TSG T7008-2023',
        "toolboxCode": '',
        "otherInstruments": '',
        "suggest": baseInfo.hadNoPass,
        "conclusion": getIsAllPass() ? 1 : 0,
        "registrationNo": dInfo.useRegistrationCode,
        "remark": '',
        "itemList": [],
        "detectId": '',
        "detectName": '',
        "productIdentifier": baseInfo.productIdentifier,
        "factoryNo": baseInfo.detectionDate,
        "detectionDate": baseInfo.detectionDate,
        "rectification": baseInfo.rectification,
        "nextYear": baseInfo.nextYear,
        "expirationDate": baseInfo.expirationDate,
    }

    if (multipleSelection.value.length > 0) {
        let str = []
        multipleSelection.value.map(item => {
            str.push(item.id)
        })
        result.otherInstruments = str.join(',')
    } else {
        isOk = false
        proxy.$modal.msgError("至少选择一个检测仪器");
    }

    if (checkItemList.value.length > 0) {
        let itemsList = []
        for (let i = 0; i < checkItemList.value.length; i++) {
            let item = checkItemList.value[i];
            itemsList.push({
                "detectionItemId": item.id,
                "chooseResult": item.chooseItemValue,
                "inputItemsResult": "",
                "remark": item.remark,
                "imgs": "",
                "videos": "",
                "isCheck": 1,
                "content": ""
            })
            if (!item.chooseItemValue) {
                isOk = false
                proxy.$modal.msgError("存在未选择符合情况的检测项");
                break
            }
        }
        result.itemList = itemsList
    }
    return {
        isOk,
        result
    }
}

defineExpose({
    getInputInfo,
})

</script>


<style lang="scss" scoped>
::v-deep(.el-table__expand-icon) {
    display: none;
    height: 0px !important;
}

.note-div {
    margin: 20px;
    font-size: 14px;
    color: #000;

    .note-item {
        margin: 5px 0;
        word-break: break-all;
        line-height: 22px;
    }
}

.el-input {
    min-width: 370px;
}

.el-select {
    width: 90px;
    min-width: 90px;
}

::v-deep(.el-form-item__label) {
    min-width: 130px !important;
}

.el-form-item {
    flex: 1;
    padding: 0 20px;
}

.form-container {
    width: 100%;
    border-radius: 10px;
    padding: 30px 0;

    .form-item-title {
        margin: 20px;
        padding: 15px 10px;
        font-weight: bold;
        color: #000;
        background: #f8f8f8;
    }

    .content-item {
        margin: 20px 100px;
    }

    .red-item {
        color: red !important;
    }
}

.detection-item-root {
    color: #000;

    .txt-item {
        word-break: break-all;
        text-align: left !important;
        margin-bottom: 5px;
        color: #000;
        margin-left: 10px;
    }

    ::v-deep(.el-textarea) {
        width: 130px !important;
        min-width: 130px !important;
    }

    .attention-item {
        word-break: break-all;
        text-align: left !important;
        margin-bottom: 5px;
        font-size: 13px;
        color: #666;
        margin-left: 20px;
        margin-top: 10px;

        .txt {
            flex: 1;
        }

        .attention-idx {
            width: 15px;
            height: 15px;
            line-height: 15px;
            text-align: center;
            border-radius: 30px;
            border: 1px #333 solid;
            margin-right: 10px;
            margin-top: 2px;
        }
    }

    .attention-title {
        width: 100%;
        font-size: 14px;
        margin-top: 10px;
        text-align: left !important;
        color: #666;
        margin-left: 20px;
    }
}

.radio-class {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding-left: 100px;
}

.checkitemop-div {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px;
}

.file-item-div {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #000;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;

    &:hover {
        background: #ddd;
    }

    .txt {
        flex: 1;
        margin-right: 5px;
        word-break: break-all;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
}

.schedule-root {
    width: 1000px;
    margin: 20px auto;
    border-top: 1px #ddd solid;
    border-right: 1px #ddd solid;

    .table-title {
        color: #333;
        font-size: 14px;
        padding: 20px;
        text-align: center;
        font-weight: bold;
        border-left: 1px #ddd solid;
        border-bottom: 1px #ddd solid;
    }

    .schedule-two-item {
        border-left: 1px #ddd solid;

        .title {
            color: #333;
            font-size: 14px;
            height: 60px;
            line-height: 60px;
            padding-left: 30px;
            font-weight: bold;
        }

        .item {
            width: 100%;
            border-top: 1px #ddd solid;
            border-right: 1px #ddd solid;
            border-bottom: 1px #ddd solid;

            .c-title {
                height: 50px;
                line-height: 50px;
                text-align: center;
                color: #666;
                font-weight: bold;
                border-bottom: 1px #ddd solid;
            }

            .el-input {
                min-width: 140px;
                height: 50px;
                line-height: 50px;
                text-align: center;
                border: none;
            }

            ::v-deep(.el-input__wrapper) {
                box-shadow: none !important;
            }

            ::v-deep(.el-input__inner) {
                text-align: center;
            }
        }
    }

    .item-title {
        color: #333;
        font-size: 14px;
        height: 40px;
        line-height: 40px;
        margin-top: 30px;
        font-weight: bold;
    }

    .table-3-container {
        padding: 30px;
        border-left: 1px #ddd solid;

        .method-item {

            ::v-deep(.el-checkbox__label) {
                display: inline-grid !important;
                white-space: pre-line !important;
                word-wrap: break-word !important;
                overflow: hidden !important;
                padding-right: 10px !important;
            }

            .cbox-item {
                margin: 10px 0;

                div {
                    line-height: 22px;
                    word-break: break-all;
                }
            }
        }

        .h-item {
            display: flex;
            width: 100%;
            height: 60px;
            line-height: 60px;
            border-top: 1px #ddd solid;
            border-left: 1px #ddd solid;
            border-right: 1px #ddd solid;

            .item {
                width: 150px;
                text-align: center;
                border-right: 1px #ddd solid;
            }

            .input-div {
                flex: 1;
                margin: 1px;
                border-right: 1px #ddd solid;
            }

            .el-input {
                height: 55px;
                line-height: 55px;
                min-width: 100px;
            }

            ::v-deep(.el-input__wrapper) {
                box-shadow: none !important;
            }

            ::v-deep(.el-input__inner) {
                text-align: center;
            }
        }
    }

    .table-floor-root {
        overflow: hidden;
        border-left: 1px #ddd solid;

        .floor-title {
            width: 100px;
            height: 41px;
            line-height: 41px;
            text-align: center;
            border-right: 1px #ddd solid;
            border-bottom: 1px #ddd solid;
            border-top: 1px #ddd solid;
            border-radius: 5px;
            margin-top: -2px;
            background: #f8f8f8;
        }

        .floor-item {
            display: flex;
            align-items: center;
            overflow-x: auto;
            flex: 1;
            height: 80px;
            text-align: center;
            border-right: 1px #ddd solid;
            border-bottom: 1px #ddd solid;

            .floor {
                height: 40px;
                line-height: 40px;
            }

            .value {
                height: 40px;
                line-height: 40px;
            }
        }

        ::v-deep(.el-input) {
            width: 100px;
            height: 40px;
            line-height: 40px;
            min-width: 100px;
        }
    }
}
</style>